package com.abocode.aichat.server.worker;

import com.abocode.aichat.server.channel.ChannelWrapper;
import com.abocode.aichat.server.reply.Replies;
import com.abocode.aichat.server.stanza.Stanza;
import com.abocode.aichat.server.stanza.StanzaHandler;
import com.abocode.aichat.server.reply.Replies;
import io.netty.channel.Channel;

/**
 * Created by franky-21.
 */
public class ProtocolStanzaWorker extends StanzaWorker {
    @Override
    public void execute(Channel channel, Stanza stanza) {
        StanzaHandler stanzaHandler = stanzaHandlerContext.get(stanza);
        ChannelWrapper channelWrapper = serverRuntimeContext.getProtocolChannelRegistry().get(channel);
        if (channelWrapper == null) {
            throw new RuntimeException("channelWrapper is not register");
        }
        Replies replies = stanzaHandler.handler(channelWrapper, stanza);
        serverRuntimeContext.getInboundServerDeliver().deliver(replies, stanza);
    }
}
